package engine;

import java.awt.Graphics2D;

import resources.ResMgr;
import resources.Sprite;
import utils.MyException;
import utils.OOBB;
import utils.Point;

class Spritable {
	private Sprite sprite;
	private float sprIndex = 0;
	float sprSpeed = 1;
	private int sprIndexOOBB = OOBB.STARTOVER;
	private Point sprScale = new Point(1, 1);
	private float sprAngle = 0;

	public float getRadius() {
		return sprite.getRadius((int) sprIndex, sprIndexOOBB) * (sprScale.getX() + sprScale.getY()) / 2;
	}

	public void paint(Graphics2D g, int x, int y) {
		sprite.paint(g, x, y, (int) getSprIndex(), getSprIndexOOBB(), getSprXScale(), getSprYScale(), getSprAngle());
	}

	public Sprite getSpr() {
		return sprite;
	}

	public int getSprIndexOOBB() {
		return sprIndexOOBB;
	}

	public float getSprIndex() {
		return sprIndex;
	}

	public float getSprSpeed() {
		return sprSpeed;
	}

	public float getSprAngle() {
		return sprAngle;
	}

	public float getSprXScale() {
		return sprScale.getX();
	}

	public float getSprYScale() {
		return sprScale.getY();
	}

	public void setSpr(String sprName) {
		try {
			sprite = (Sprite) ResMgr.get().get(sprName);
		} catch (MyException e) {
			e.printStackTrace();
			sprite = Sprite.NULL;
		}
	}

	public void setSprIndexOOBB(int sprIndexOOBB) {
		this.sprIndexOOBB = sprIndexOOBB;
	}

	public void setSprIndex(float f) {
		this.sprIndex = f;
	}

	public void setSprSpeed(float f) {
		this.sprSpeed = f;
	}

	public void setSprAngle(float sprAngle) {
		this.sprAngle = sprAngle;
	}

	public void setSprXScale(float xScale) {
		sprScale = sprScale.set(xScale, sprScale.getY());
	}

	public void setSprYScale(float yScale) {
		sprScale = sprScale.set(sprScale.getX(), yScale);
	}

	void step(float fpsFactor) {
		setSprIndex(getSprIndex() + getSprSpeed() * fpsFactor);
	}
}
